// 提供复用逻辑函数（钩子） target dom对象
import { useIntersectionObserver } from '@vueuse/core';
import { ref } from 'vue';
export const useLazyData = (apiFn) => {
	const result = ref([]);
	const target = ref(null);
	const { stop } = useIntersectionObserver(
		target,
		([ { isIntersecting } ], observerElement) => {
			if (isIntersecting) {
				stop();
				apiFn().then((data) => {
					result.value = data.result;
				});
			}
		},
		{
			threshold: 0
		}
	);
	return { result, target };
};
